package com.xnck.example.sbtest.service;

import com.xnck.example.sbtest.entity.AppInfo;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class AppService {

    public int getCount() {
        return 35;
    }

    public List<AppInfo> getsByPage(int pageNo, int pageSize) {
        List<AppInfo> apps = createAppInfoList();
        return apps.stream().skip((pageNo - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
    }

    private List<AppInfo> createAppInfoList () {
        List<AppInfo> apps = new ArrayList<>();
        for (int i = 0; i < 35; i++) {
            AppInfo app = new AppInfo();
            app.setAppcode("APP-" + i);
            app.setAppname("应用程序-" + i);
            app.setCreatedate(new Date());
            app.setCreater("管理员");
            app.setCreaterid("Admin");
            app.setId(String.valueOf(i));
            app.setUpdatedate(new Date());
            app.setUpdater("管理员");
            app.setUpdaterid("Admin");
            apps.add(app);
        }
        return apps;
    }
}
